<template>
  <div class="detail-wrapper">
    <div class="detail-main">
      <div class="detail-column">
        <div class="column-title">基础信息</div>
        <div class="column-content">
          <a-descriptions
            bordered
            :labelStyle="{ width: '150px' }"
            :contentStyle="{ width: '500px' }"
            :column="{ xxl: 2, xl: 2, lg: 2, md: 1, sm: 1, xs: 1 }"
          >
            <a-descriptions-item label="会员名称">{{ memberData?.user?.real_name || '-' }}</a-descriptions-item>
            <a-descriptions-item label="注册账号">{{ memberData?.user?.login_name || '-' }}</a-descriptions-item>
            <a-descriptions-item label="绑定微信" >
              {{ memberData?.user?.weixins?.[0]?.open_id ? '已绑定' : '未绑定' }}
            </a-descriptions-item>
            <a-descriptions-item label="当前状态">
               {{ memberData?.enabled ? '启用' : '禁用' }}
            </a-descriptions-item>
            <a-descriptions-item label="注册日期" >
              {{ memberData?.user?.create_time || '-' }}
            </a-descriptions-item>
            <a-descriptions-item label="会员激活时间" >
              {{ memberData?.created || '-' }}
            </a-descriptions-item>
          </a-descriptions>
        </div>
      </div>
      <div class="detail-column">
        <div class="column-title">会员策略信息</div>
        <div class="column-content">
          <a-descriptions
            bordered
            :labelStyle="{ width: '150px' }"
            :contentStyle="{ width: '500px' }"
            :column="{ xxl: 2, xl: 2, lg: 2, md: 1, sm: 1, xs: 1 }"
          >
            <a-descriptions-item label="策略名称">{{ memberData?.strategy?.name || '-' }}</a-descriptions-item>
            <a-descriptions-item label="策略描述">{{ memberData?.strategy?.description || '-' }}</a-descriptions-item>
            <a-descriptions-item label="年费(￥)">
              ¥{{ memberData?.strategy?.annual_fee || 0 }}
            </a-descriptions-item>
            <a-descriptions-item label="AI功能">
               {{ memberData?.strategy?.ai_enabled ? '启用' : '禁用' }}
            </a-descriptions-item>
            <a-descriptions-item label="非会员Token">
              {{ memberData?.strategy?.tokens_non_member || 0 }}
            </a-descriptions-item>
            <a-descriptions-item label="会员Token">
              {{ memberData?.strategy?.tokens_for_member || 0 }}
            </a-descriptions-item>
          </a-descriptions>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, computed, onMounted } from "vue";
import { useRoute } from "vue-router";
import API from "@/api/administrator";

const route = useRoute();
const query = computed(() => route.query);
const memberData = ref(null);



// 获取会员详情数据
const getMemberData = async () => {
  try {
    const params = {
      user_id: query.value.user_id, // 从路由参数获取user_id
    };
    console.log("请求参数:", params);
    console.log("路由参数:", query.value);
    
    const res = await API.MembershipFetchModel(params);
    console.log("API返回结果:", res);
    
    if (res.succeeded) {
      memberData.value = res.data;
      console.log("获取到的会员详情:", res.data);
      console.log("memberData.value:", memberData.value);
    } else {
      console.error("API调用失败:", res);
      // 如果API调用失败，使用测试数据
      const testData = {
        "user_id": "u1",
        "strategy_id": "s1",
        "remark": "测试",
        "enabled": true,
        "created": "2024-01-02 10:00:00",
        "updated": null,
        "user": {
          "user_id": "u1",
          "login_name": "test_user",
          "real_name": "张三",
          "mobile": "13800138000",
          "create_time": "2024-01-01 09:00:00",
          "enabled": true,
          "weixins": [
            {
              "open_id": "wx123456",
              "user_id": "u1"
            }
          ]
        },
        "strategy": {
          "strategy_id": "s1",
          "name": "会员模式1",
          "description": "测试会员策略",
          "annual_fee": 99,
          "ai_enabled": true,
          "tokens_non_member": 200,
          "tokens_for_member": 3000,
          "enabled": true
        }
      };
      memberData.value = testData;
      console.log("使用测试数据:", testData);
    }
  } catch (error) {
    console.error("获取会员详情失败:", error);
    // 如果出现异常，使用测试数据
    const testData = {
      "user_id": "u1",
      "strategy_id": "s1",
      "remark": "测试",
      "enabled": true,
      "created": "2024-01-02 10:00:00",
      "updated": null,
      "user": {
        "user_id": "u1",
        "login_name": "test_user",
        "real_name": "张三",
        "mobile": "13800138000",
        "create_time": "2024-01-01 09:00:00",
        "enabled": true,
        "weixins": [
          {
            "open_id": "wx123456",
            "user_id": "u1"
          }
        ]
      },
      "strategy": {
        "strategy_id": "s1",
        "name": "会员模式1",
        "description": "测试会员策略",
        "annual_fee": 99,
        "ai_enabled": true,
        "tokens_non_member": 200,
        "tokens_for_member": 3000,
        "enabled": true
      }
    };
    memberData.value = testData;
    console.log("异常情况下使用测试数据:", testData);
  }
};

onMounted(() => {
  getMemberData();
});
</script>

